import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/entity/team/zq_team_detail_entity.dart';
import 'package:ball_lion/entity/team/zq_team_lineup_entity.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/resources/styles.dart';
import 'package:ball_lion/utils/utils.dart';
import 'package:ball_lion/widgets/base/wqs_text.dart';

class PlayerValueItem extends StatelessWidget {
  const PlayerValueItem(
      {super.key,
      required this.lineup,
      required this.detail,
      required this.section});

  final int section;
  final SoccerTeamDetailEntity? detail;
  final SoccerTeamLineupEntity? lineup;

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        //if (section != 0)
        Container(
            height: 36,
            width: Get.width,
            padding: const EdgeInsets.symmetric(horizontal: 20),
            decoration: const BoxDecoration(color: Colours.greyF2F3F7),
            child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  QsText(
                    lineup!.title!,
                    fontSize: 14,
                    color: Colours.N9,
                    fontWeight: FontWeight.w500,
                  ),
                  QsText(
                      (detail?.type != "1" && detail?.type != "2")
                          ? "身价(英镑)"
                          : "俱乐部/身价(英镑)",
                      fontSize: 12,
                      color: Colours.N8)
                ])),
        ListView.separated(
            padding: EdgeInsets.zero,
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemCount: lineup?.player?.length ?? 0,
            separatorBuilder: (context, index) => const Divider(
                height: 0.5,
                color: Colours.transparent,
                indent: 16,
                endIndent: 16),
            itemBuilder: (context, index) {
              return (0 == section)
                  ? CoachInfoCell(
                      index: index,
                      player: lineup!.player![index],
                    )
                  : PlayerInfoCell(
                      index: index,
                      player: lineup!.player![index],
                    );
            }),
      ],
    );
  }
}

class CoachInfoCell extends StatelessWidget {
  const CoachInfoCell(
      {super.key,
      required this.player,
      required this.index,
      this.padding = 16,
      this.needColor = true});

  final int index;
  final double padding;
  final bool needColor;
  final Player? player;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
        height: 98,
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
          child: Container(
              padding: const EdgeInsets.symmetric(horizontal: 12),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(8),
                  color: Colours.greyF2F3F7),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  CachedNetworkImage(
                    height: 55,
                    width: 55,
                    fit: BoxFit.cover,
                    imageUrl: player?.photo ?? "",
                    placeholder: (context, url) => Styles.placeholderIcon(),
                    errorWidget: (context, url, error) => Image.asset(
                      Utils.getImgPath('zq_placeholder.png'),
                      height: 32,
                      width: 24,
                    ),
                  ),
                  Container(width: 8),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Flexible(
                          child: QsText(player?.playerCn ?? "", fontSize: 13)),
                      Container(height: 4),
                      if ((player?.number != null && player?.number != ""
                                  ? "${player!.number}号\u2000"
                                  : "") +
                              (player?.age != null && player?.age != ""
                                  ? "${player!.age}岁\u2000"
                                  : "") +
                              (player?.countryCn != null &&
                                      player?.countryCn != "" &&
                                      (null != player?.countryCn)
                                  ? "${player?.countryCn}"
                                  : "") !=
                          "")
                        QsText(
                            (player?.number != null && player?.number != ""
                                    ? "${player!.number}号\u2000"
                                    : "") +
                                (player?.age != null && player?.age != ""
                                    ? "${player!.age}岁\u2000"
                                    : "") +
                                (player?.countryCn != null &&
                                        player?.countryCn != "" &&
                                        (null != player?.countryCn)
                                    ? "${player?.countryCn}"
                                    : ""),
                            fontSize: 11,
                            color: Colours.N7)
                    ],
                  ),
                  const Spacer(),
                  QsText(
                      player?.value != null &&
                              player?.value != "" &&
                              double.parse(player?.value ?? "0") > 0
                          ? "${player!.value}万"
                          : "-",
                      fontSize: 13)
                ],
              )),
        ));
  }
}

class PlayerInfoCell extends StatelessWidget {
  const PlayerInfoCell(
      {super.key,
      required this.player,
      required this.index,
      this.padding = 16,
      this.needColor = true});

  final int index;
  final double padding;
  final bool needColor;
  final Player? player;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
        height: 50,
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 20),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              CachedNetworkImage(
                height: 32,
                width: 24,
                fit: BoxFit.cover,
                imageUrl: player?.photo ?? "",
                placeholder: (context, url) => Styles.placeholderIcon(),
                errorWidget: (context, url, error) => Image.asset(
                  Utils.getImgPath('zq_placeholder.png'),
                  height: 32,
                  width: 24,
                ),
              ),
              Container(width: 8),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Flexible(child: QsText(player?.playerCn ?? "", fontSize: 13)),
                  if ((player?.number != null && player?.number != ""
                              ? "${player!.number}号\u2000"
                              : "") +
                          (player?.age != null && player?.age != ""
                              ? "${player!.age}岁\u2000"
                              : "") +
                          (player?.countryCn != null &&
                                  player?.countryCn != "" &&
                                  (null != player?.countryCn)
                              ? "${player?.countryCn}"
                              : "") !=
                      "")
                    QsText(
                        (player?.number != null && player?.number != ""
                                ? "${player!.number}号\u2000"
                                : "") +
                            (player?.age != null && player?.age != ""
                                ? "${player!.age}岁\u2000"
                                : "") +
                            (player?.countryCn != null &&
                                    player?.countryCn != "" &&
                                    (null != player?.countryCn)
                                ? "${player?.countryCn}"
                                : ""),
                        fontSize: 11,
                        color: Colours.N7)
                ],
              ),
              const Spacer(),
              QsText(
                  player?.value != null &&
                          player?.value != "" &&
                          double.parse(player?.value ?? "0") > 0
                      ? "${player!.value}万"
                      : "-",
                  fontSize: 13)
            ],
          ),
        ));
  }
}
